let threadManage = require('./thread_manage');

const commandArgs = ['client','server'];

let args = process.argv.splice(2);
//参数去重
args = [...new Set(args)];

if(args && args.length > 0){
    //检查是否存在未定义参数
    args.forEach(function (arg,index,array) {
        if(commandArgs.indexOf(arg) === -1){
            throw new Error('Unknown command args:[' + arg + ']');
        }
    });

    //根据参数启动对应线程
    args.forEach(function (arg,index,array) {
        if('client' === arg){
            threadManage.activeDownloadThread();
        }
        if('server' === arg){
            require('./server/server');
        }
    })
}


///////////////////////////////////////////////////////////////////
String.prototype.render = function (context) {
    return this.replace(/{{(.*?)}}/g, (match, key) => context[key.trim()]);
};

